/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-09-20 17:58:03
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-03 14:46:54
 * @FilePath: /GateServer/src/net/httpconnection.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */


#pragma once
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/http/dynamic_body.hpp>
#include <boost/beast/http/message.hpp>
#include <chrono>
#include <memory>
#include <unordered_map>
#include"../util/global.h"

namespace Yizhi { 
    class HttpConnection:public std::enable_shared_from_this<HttpConnection> {
        friend class LogicSystem;
        public:
        typedef std::shared_ptr<HttpConnection> ptr;
        HttpConnection(net::io_context& ioc);
        void start();


        tcp::socket& getsokcet(){
            return m_socket;
        }
        private:

        void HandleReq();
        void WriteResponse();
        void CheckDeadline();
        void Preparseparams();


        ///socket
        tcp::socket m_socket;

        ///缓存
        beast::flat_buffer m_buf{8192};

        ///请求体
        http::request<http::dynamic_body> m_request;

        ///返回体
        http::response<http::dynamic_body> m_response;

        ///url
        std::string m_get_url;

        ///定时器
        net::steady_timer m_deadline{
            m_socket.get_executor(),std::chrono::seconds(60)
        };
        
        std::unordered_map<std::string,std::string> m_getparams;
        
        
    };
    
    
}